\ Preprocessor FOOS delegation demo - Copyright 2012 J.L. Bezemer
\ You can redistribute this file and/or modify it under
\ the terms of the GNU General Public License

\ Translation of:
\   http://en.wikipedia.org/wiki/Delegation_%28programming%29

include 4pp/lib/foos.4pp

:: A
   class
     method: foo
     method: bar
   end-class {

     :method { this => bar }  ; defines foo
     :method { ." a.bar" cr } ; defines bar
   }
;

:: B
   extends A
     field: (a)                        \ delegation link
   end-extends {

     this -> (a) !                     \ call foo on the (a)-instance
     :method { this -> (a) @ => foo } ; defines foo
     :method { ." b.bar" cr }         ; defines bar
   }

   private{ (a) }
;

static A MyA
MyA static B MyB                       \ create delegation between two objects
                                       \ will result in "a.bar" being 
MyB => foo                             \ printed, since class B "delegates"
                                       \ method foo to an object of class A